package com.newtouch.bxzs.database.synchronize.batch.step;

import com.newtouch.bxzs.database.synchronize.batch.reader.ReaderData;
import com.newtouch.bxzs.database.synchronize.batch.writer.WriterIncome;
import com.newtouch.bxzs.database.synchronize.model.income.IncomeDetailVO;
import com.newtouch.bxzs.database.synchronize.model.income.IncomeEstimateVO;
import com.newtouch.bxzs.database.synchronize.model.income.IncomeVO;
import org.springframework.batch.core.Step;
import org.springframework.batch.core.configuration.annotation.StepBuilderFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 收入同步step
 *
 * <p>
 * <b>History:</b>
 * <table border="1">
 * <tr>
 * <th>Date</th>
 * <th>Operator</th>
 * <th>Memo</th>
 * </tr>
 * <tr>
 * <td>2021/1/8 13:45</td>
 * <td>Amour</td>
 * <td>Create</td>
 * </tr>
 * </table>
 *
 * @author yuanjie
 * @version 1.0.0
 * @since 1.0.0
 */
@Component
public class IncomeStep {
    @Autowired
    private StepBuilderFactory stepBuilderFactory;

    @Autowired
    private ReaderData readerData;

    @Autowired
    private WriterIncome writerIncome;


    /**批处理同步收入数据*/
    public Step synchronizeIncomeStep(){
        return stepBuilderFactory.get("synchronizeIncomeStep")
                .<IncomeVO, IncomeVO>chunk(1000)
                .reader(readerData.getIncome())
                .writer(writerIncome.addIncomeList())
                .faultTolerant()
                .skip(Exception.class)
                .skipLimit(10)
                .build();
    }

    /**批处理同步收入明细数据*/
    public Step synchronizeIncomeDetailStep(){
        return stepBuilderFactory.get("synchronizeIncomeDetailStep")
                .<IncomeDetailVO, IncomeDetailVO>chunk(1000)
                .reader(readerData.getIncomeDetail())
                .writer(writerIncome.addIncomeDetailList())
                .faultTolerant()
                .skip(Exception.class)
                .skipLimit(10)
                .build();
    }

    /**批处理同步预估收入数据*/
    public Step synchronizeIncomeEstimateStep(){
        return stepBuilderFactory.get("synchronizeIncomeEstimateStep")
                .<IncomeEstimateVO, IncomeEstimateVO>chunk(1000)
                .reader(readerData.getIncomeEstimate())
                .writer(writerIncome.addIncomeEstimateList())
                .faultTolerant()
                .skip(Exception.class)
                .skipLimit(10)
                .build();
    }

    /**批处理同步收入数据*/
    public Step synchronizeIncomeEstimateDetailStep(){
        return stepBuilderFactory.get("synchronizeIncomeEstimateDetailStep")
                .<IncomeDetailVO, IncomeDetailVO>chunk(1000)
                .reader(readerData.getIncomeEstimateDetail())
                .writer(writerIncome.addIncomeEstimateDetailList())
                .faultTolerant()
                .skip(Exception.class)
                .skipLimit(10)
                .build();
    }
}
